function User(id){
	this.id=id;
	this.name=null;
	this.status=null;

	this.lastActivity = null;
	this.messageCounter = 0;

	this.dom = null;

	this.statusName = ['offline', 'online', 'away', 'typing'];

	if(isNumeric(id)) global.addObjectItem('user',this,this.getKey());
}

User.prototype.getKey = function(name){
	return 'user_'+this.id;
}

User.prototype.assignProperties = function(name,administrator,status){
	this.name = name;
	this.status = status;
	this.administrator = administrator;
}

User.prototype.getPicturePath = function(type){
	if(type) type = '?type='+type;
	else type = '';

	return 'http://graph.facebook.com/'+this.id+'/picture'+type;
}

User.prototype.createRoomMemberItem = function(clone){
	if(this.dom != null) return this.dom.element;
	//if(getDom) return this.dom.element;
	if(clone) return this.dom.element.cloneNode(true);

	var user = document.createElement('DIV');
	user.className = 'user item '+this.getStatusName();

	var name = document.createElement('P');
	name.className = 'name';
	name.appendChild(document.createTextNode(this.name));

	var status = document.createElement('P');
	status.className = 'status '+this.getStatusName();

	var picture = document.createElement('DIV');
	var img = document.createElement('IMG');
	picture.className = 'picture';
	img.src = this.getPicturePath();
	picture.appendChild(img);

	setData(user, 'key', this.getKey());
	
	user.appendChild(picture);
	user.appendChild(name);
	user.appendChild(status);

	setEvent(user,'mouseover',showInformationBox);
	setEvent(user,'mouseout',hideInformationBox);

	this.dom = {element: user, name: name, status: status, picture: picture};

	return user;
}

User.prototype.assignObject = function(obj){
	for(var property in obj){
		this[property] = obj[property];
	}
}

User.prototype.changeStatus = function(status){
	var oldListName,newListName;
	
	/*if(status == 2){
		alert(status)
		alert(this.status)	
	} */

	if(! ( (status == 3 && this.status == 1) || (status == 1 && this.status == 3) ) ){
		oldListName = getUserListName(this.status);
		newListName = getUserListName(status);	
		global.getObject('room').updateUserList(this,oldListName,newListName);
	}	

	this.status = status;
	this.dom.element.className = 'user item '+this.getStatusName();

	var me = global.getObject('me');
	if(me.id == this.id) me.setAwayTimer();
}

User.prototype.getStatusName = function(){
	return this.statusName[this.status];
}

User.prototype.setLastActivity = function(lastActivity){
	this.lastActivity = lastActivity;
}

function showInformationBox(event){
	var user = findParentWithClass(event.target,'user');
	
	global.getObject('UserInformationBox').show(getData(user,'key'));
}

function hideInformationBox(event){
	var caller = event.target;
	var callerIsUserInformationBox = findParentWithClass(event.relatedTarget, 'userInformationBox',true);
	var mouseOnElement;
	if(!callerIsUserInformationBox) mouseOnElement = 'userInformationBox';
	else mouseOnElement = 'user';

	var element = findParentWithClass(event.relatedTarget, mouseOnElement,true);
	if(element == false) global.getObject('UserInformationBox').hide();
}

function getUserListName(status){
	var listName;

	if(status == 1 || status == 3) listName = 'usersOnline';
	if(status == 2) listName = 'usersAway';
	if(status == 0) listName = 'usersOffline';

	return listName;
}